// 导航样式
$("#nav a").on("click", function(e) {
  e.preventDefault(); // 阻止默认链接行为
  var $this = $(this);
  var position = $this.parent().position();
  var width = $this.parent().width();
  
  // 动画持续时间
  var DonghuaTime = 450;

  $("#nav .slide-one").css({ opacity: 1, left: position.left, width: width });

  // 动画结束后的跳转
  setTimeout(function() {
      window.location.href = $this.attr("href"); // 跳转到链接
  }, DonghuaTime);
});

// 初始设置slide-one的位置和宽度
$(document).ready(function() {
  var currentWidth = $("#nav li:nth-of-type(3) a").parent("li").width();
  var current = $("#nav li:nth-of-type(3) a").parent("li").position();
  $("#nav .slide-one").css({ left: current.left, width: currentWidth, opacity: 1 }); // 初始设置就显示，不需要等待动画
});
// 轮播图
let currentIndex = 0;
const images = document.querySelectorAll('.image-container img');
const dots = document.querySelectorAll('.dots-container .dot');
const totalImages = images.length;

// 初始化，显示第一张图片和对应的小圆点
images[0].classList.add('active');
dots[0].classList.add('active');

function showImage(index) {
    // 隐藏所有图片和小圆点
    images.forEach(img => img.classList.remove('active'));
    dots.forEach(dot => dot.classList.remove('active'));

    // 显示指定索引的图片和对应的小圆点
    images[index].classList.add('active');
    dots[index].classList.add('active');

    // 更新currentIndex
    currentIndex = index;
}

function NextImage() {
    showImage((currentIndex + 1) % totalImages);
}

function PrevImage() {
    showImage((currentIndex - 1 + totalImages) % totalImages);
}

// 设置定时器
let imageInterval = setInterval(NextImage, 3000);

// 设置上一张和下一张图片按钮
document.querySelector('.next-btn').addEventListener('click', NextImage);
document.querySelector('.prev-btn').addEventListener('click', PrevImage);

// 为每个小圆点添加点击事件监听器
dots.forEach((dot, index) => {
    dot.addEventListener('click', () => {
        showImage(index);
        // 清除定时器，防止自动切换干扰手动选择
        clearInterval(imageInterval);
    });
});

// 在某个时候恢复自动切换图片
setInterval(NextImage, 6000);



// 虚化
const p = document.querySelector('.container.p');
const fazhan = document.querySelector('.container.fazhan');
const background = document.querySelector('.container.filter-1');
const background1 = document.querySelector('.container.filter-2');
p.addEventListener('mouseenter', function() {
  background.classList.add('blur');
});

p.addEventListener('mouseleave', function() {
  background.classList.remove('blur');
});
fazhan.addEventListener('mouseenter', function() {
  background1.classList.add('blur');
});

fazhan.addEventListener('mouseleave', function() {
  background1.classList.remove('blur');
});

// 隐藏和展开
document.addEventListener('DOMContentLoaded', function() {
  var showMore = document.querySelector('.show-more');
  var textHidden = document.querySelector('.text-hidden');

  showMore.addEventListener('click', function(e) {
    textHidden.style.display = textHidden.style.display === 'block' ? 'none' : 'block';
    this.textContent = this.textContent === '查看更多' ? '隐藏' : '查看更多';
  });
});
// 用于展开内容
document.getElementById(".show-more").addEventListener("click", function() {

  window.scrollTo(0, document.body.scrollHeight);
});